// $Id$
/*
 *  Copyright (C) 2007 NourY Solutions
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 3 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 */
/*! \file
 * \brief Assembly configuration information.
 *
 * \author $Author$
 * \date $Date$
 * \version $Revision$
 */

using System.Configuration;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data.Oracle.Configuration;
using MsOracle=Microsoft.Practices.EnterpriseLibrary.Data.Oracle;

namespace Salamanca.DataAccess.EnterpriseLibrary.Data.Oracle
{
    internal class OracleDatabaseAssembler:
        IDatabaseAssembler
    {
        public Database Assemble(string name, ConnectionStringSettings connectionStringSettings, IConfigurationSource configurationSource)
        {
            OracleConnectionSettings oracleConnectionSettings=OracleConnectionSettings.GetSettings(configurationSource);
            if (oracleConnectionSettings!=null)
            {
                OracleConnectionData oracleConnectionData=oracleConnectionSettings.OracleConnectionsData.Get(name);
                if (oracleConnectionData!=null)
                {
                    ArrayList packages=new ArrayList(oracleConnectionData.Packages);
                    return new OracleDatabase(connectionStringSettings.ConnectionString, (MsOracle.IOraclePackage[])packages.ToArray(typeof(MsOracle.IOraclePackage)));
                }
            }

            return new OracleDatabase(connectionStringSettings.ConnectionString);
        }
    }
}
